package com.dk.service.impl;

import com.dk.mapper.TAuthorMapper;
import com.dk.pojo.TAuthor;
import com.dk.pojo.TAuthorExample;
import com.dk.service.AuthorService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthorServiceImpl implements AuthorService {

    @Autowired
    private TAuthorMapper AuthorMapper;


    @Override
    public PageInfo<TAuthor> getInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TAuthor> list = AuthorMapper.getInfo();
        PageInfo<TAuthor> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public int add(TAuthor author) {
        return AuthorMapper.insert(author);
    }

    @Override
    public List<TAuthor> getInfoByChannnel() {
        return AuthorMapper.getInfoByChannnel();
    }

    @Override
    public TAuthor toUpdate(Integer authorId) {
        return AuthorMapper.selectByPrimaryKey(authorId);
    }

    @Override
    public int updateChannel(TAuthor author) {
        return AuthorMapper.updateByPrimaryKeySelective(author);
    }

    @Override
    public int deleteInfoById(Integer authorId) {
        return AuthorMapper.deleteByPrimaryKey(authorId);
    }

    @Override
    public List<TAuthor> selectAuthor() {
        TAuthorExample example = new TAuthorExample();
        List<TAuthor> list = AuthorMapper.selectByExample(example);
        return list;
    }
}
